<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>libwebsockets: Callback when writeable</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="libwebsockets.org-logo.png"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">libwebsockets
   </div>
   <div id="projectbrief">Lightweight C library for HTML5 websockets</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li class="current"><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('group__callback-when-writeable.html','');});
</script>
<div id="doc-content">
<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">Callback when writeable</div>  </div>
</div><!--header-->
<div class="contents">
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ga941caaa468bc507b1cae52275f58800d"><td class="memItemLeft" align="right" valign="top">LWS_VISIBLE LWS_EXTERN int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__callback-when-writeable.html#ga941caaa468bc507b1cae52275f58800d">lws_callback_on_writable</a> (struct lws *wsi)</td></tr>
<tr class="separator:ga941caaa468bc507b1cae52275f58800d"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gabbe4655c7eeb3eb1671b2323ec6b3107"><td class="memItemLeft" align="right" valign="top">LWS_VISIBLE LWS_EXTERN int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__callback-when-writeable.html#gabbe4655c7eeb3eb1671b2323ec6b3107">lws_callback_on_writable_all_protocol</a> (const struct lws_context *context, const struct <a class="el" href="structlws__protocols.html">lws_protocols</a> *protocol)</td></tr>
<tr class="separator:gabbe4655c7eeb3eb1671b2323ec6b3107"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga8570860e191b62db264f2bac67354ea8"><td class="memItemLeft" align="right" valign="top">LWS_VISIBLE LWS_EXTERN int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__callback-when-writeable.html#ga8570860e191b62db264f2bac67354ea8">lws_callback_on_writable_all_protocol_vhost</a> (const struct lws_vhost *vhost, const struct <a class="el" href="structlws__protocols.html">lws_protocols</a> *protocol)</td></tr>
<tr class="separator:ga8570860e191b62db264f2bac67354ea8"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gacf04bbe089f47c971c6408c5efe2ac70"><td class="memItemLeft" align="right" valign="top">LWS_VISIBLE LWS_EXTERN int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__callback-when-writeable.html#gacf04bbe089f47c971c6408c5efe2ac70">lws_callback_all_protocol</a> (struct lws_context *context, const struct <a class="el" href="structlws__protocols.html">lws_protocols</a> *protocol, int reason)</td></tr>
<tr class="separator:gacf04bbe089f47c971c6408c5efe2ac70"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga13c984d8c5a44a745fd02bc2fba36053"><td class="memItemLeft" align="right" valign="top">LWS_VISIBLE LWS_EXTERN int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__callback-when-writeable.html#ga13c984d8c5a44a745fd02bc2fba36053">lws_callback_all_protocol_vhost</a> (struct lws_vhost *vh, const struct <a class="el" href="structlws__protocols.html">lws_protocols</a> *protocol, int reason)</td></tr>
<tr class="separator:ga13c984d8c5a44a745fd02bc2fba36053"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga60939cf0c073d933fde3d17f3591caf5"><td class="memItemLeft" align="right" valign="top">LWS_VISIBLE LWS_EXTERN int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__callback-when-writeable.html#ga60939cf0c073d933fde3d17f3591caf5">lws_callback_vhost_protocols</a> (struct lws *wsi, int reason, void *in, int len)</td></tr>
<tr class="separator:ga60939cf0c073d933fde3d17f3591caf5"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaad3d524a84d2be08ac85153bc158504b"><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="gaad3d524a84d2be08ac85153bc158504b"></a>
LWS_VISIBLE LWS_EXTERN int&#160;</td><td class="memItemRight" valign="bottom"><b>lws_callback_http_dummy</b> (struct lws *wsi, enum <a class="el" href="group__usercb.html#gad62860e19975ba4c4af401c3cdb6abf7">lws_callback_reasons</a> reason, void *user, void *in, size_t len)</td></tr>
<tr class="separator:gaad3d524a84d2be08ac85153bc158504b"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaa709e02a10558753c851e58f1e2c16ba"><td class="memItemLeft" align="right" valign="top">LWS_VISIBLE LWS_EXTERN int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__callback-when-writeable.html#gaa709e02a10558753c851e58f1e2c16ba">lws_get_socket_fd</a> (struct lws *wsi)</td></tr>
<tr class="separator:gaa709e02a10558753c851e58f1e2c16ba"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gac4643fe16b0940ae5b68b4ee6195cbde"><td class="memItemLeft" align="right" valign="top">LWS_VISIBLE LWS_EXTERN size_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__callback-when-writeable.html#gac4643fe16b0940ae5b68b4ee6195cbde">lws_get_peer_write_allowance</a> (struct lws *wsi)</td></tr>
<tr class="separator:gac4643fe16b0940ae5b68b4ee6195cbde"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<h2>Callback When Writeable</h2>
<p>lws can only write data on a connection when it is able to accept more data without blocking.</p>
<p>So a basic requirement is we should only use the <a class="el" href="group__sending-data.html#gafd5fdd285a0e25ba7e3e1051deec1001">lws_write()</a> apis when the connection we want to write on says that he can accept more data.</p>
<p>When lws cannot complete your send at the time, it will buffer the data and send it in the background, suppressing any further WRITEABLE callbacks on that connection until it completes. So it is important to write new things in a new writeable callback.</p>
<p>These apis reflect the various ways we can indicate we would like to be called back when one or more connections is writeable. </p>
<h2 class="groupheader">Function Documentation</h2>
<a class="anchor" id="gacf04bbe089f47c971c6408c5efe2ac70"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">LWS_VISIBLE LWS_EXTERN int lws_callback_all_protocol </td>
          <td>(</td>
          <td class="paramtype">struct lws_context *&#160;</td>
          <td class="paramname"><em>context</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const struct <a class="el" href="structlws__protocols.html">lws_protocols</a> *&#160;</td>
          <td class="paramname"><em>protocol</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>reason</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p><code>#include &lt;<a class="el" href="libwebsockets_8h.html">lib/libwebsockets.h</a>&gt;</code></p>
<p><a class="el" href="group__callback-when-writeable.html#gacf04bbe089f47c971c6408c5efe2ac70">lws_callback_all_protocol()</a> - Callback all connections using the given protocol with the given reason</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">context</td><td>lws_context </td></tr>
    <tr><td class="paramname">protocol</td><td>Protocol whose connections will get callbacks </td></tr>
    <tr><td class="paramname">reason</td><td>Callback reason index</td></tr>
  </table>
  </dd>
</dl>
<ul>
<li>Which: connections using this protocol on ALL VHOSTS</li>
<li>When: when the individual connection becomes writeable</li>
<li>What: reason </li>
</ul>

</div>
</div>
<a class="anchor" id="ga13c984d8c5a44a745fd02bc2fba36053"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">LWS_VISIBLE LWS_EXTERN int lws_callback_all_protocol_vhost </td>
          <td>(</td>
          <td class="paramtype">struct lws_vhost *&#160;</td>
          <td class="paramname"><em>vh</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const struct <a class="el" href="structlws__protocols.html">lws_protocols</a> *&#160;</td>
          <td class="paramname"><em>protocol</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>reason</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p><code>#include &lt;<a class="el" href="libwebsockets_8h.html">lib/libwebsockets.h</a>&gt;</code></p>
<p><a class="el" href="group__callback-when-writeable.html#ga13c984d8c5a44a745fd02bc2fba36053">lws_callback_all_protocol_vhost()</a> - Callback all connections using the given protocol with the given reason</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">vh</td><td>Vhost whose connections will get callbacks </td></tr>
    <tr><td class="paramname">protocol</td><td>Which protocol to match </td></tr>
    <tr><td class="paramname">reason</td><td>Callback reason index</td></tr>
  </table>
  </dd>
</dl>
<ul>
<li>Which: connections using this protocol on GIVEN VHOST ONLY</li>
<li>When: now</li>
<li>What: reason </li>
</ul>

</div>
</div>
<a class="anchor" id="ga941caaa468bc507b1cae52275f58800d"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">LWS_VISIBLE LWS_EXTERN int lws_callback_on_writable </td>
          <td>(</td>
          <td class="paramtype">struct lws *&#160;</td>
          <td class="paramname"><em>wsi</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p><code>#include &lt;<a class="el" href="libwebsockets_8h.html">lib/libwebsockets.h</a>&gt;</code></p>
<p><a class="el" href="group__callback-when-writeable.html#ga941caaa468bc507b1cae52275f58800d">lws_callback_on_writable()</a> - Request a callback when this socket becomes able to be written to without blocking</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">wsi</td><td>Websocket connection instance to get callback for</td></tr>
  </table>
  </dd>
</dl>
<ul>
<li>Which: only this wsi</li>
<li>When: when the individual connection becomes writeable</li>
<li>What: LWS_CALLBACK_*_WRITEABLE </li>
</ul>

</div>
</div>
<a class="anchor" id="gabbe4655c7eeb3eb1671b2323ec6b3107"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">LWS_VISIBLE LWS_EXTERN int lws_callback_on_writable_all_protocol </td>
          <td>(</td>
          <td class="paramtype">const struct lws_context *&#160;</td>
          <td class="paramname"><em>context</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const struct <a class="el" href="structlws__protocols.html">lws_protocols</a> *&#160;</td>
          <td class="paramname"><em>protocol</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p><code>#include &lt;<a class="el" href="libwebsockets_8h.html">lib/libwebsockets.h</a>&gt;</code></p>
<p><a class="el" href="group__callback-when-writeable.html#gabbe4655c7eeb3eb1671b2323ec6b3107">lws_callback_on_writable_all_protocol()</a> - Request a callback for all connections on same vhost using the given protocol when it becomes possible to write to each socket without blocking in turn.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">context</td><td>lws_context </td></tr>
    <tr><td class="paramname">protocol</td><td>Protocol whose connections will get callbacks</td></tr>
  </table>
  </dd>
</dl>
<ul>
<li>Which: connections using this protocol on ANY VHOST</li>
<li>When: when the individual connection becomes writeable</li>
<li>What: LWS_CALLBACK_*_WRITEABLE </li>
</ul>

</div>
</div>
<a class="anchor" id="ga8570860e191b62db264f2bac67354ea8"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">LWS_VISIBLE LWS_EXTERN int lws_callback_on_writable_all_protocol_vhost </td>
          <td>(</td>
          <td class="paramtype">const struct lws_vhost *&#160;</td>
          <td class="paramname"><em>vhost</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const struct <a class="el" href="structlws__protocols.html">lws_protocols</a> *&#160;</td>
          <td class="paramname"><em>protocol</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p><code>#include &lt;<a class="el" href="libwebsockets_8h.html">lib/libwebsockets.h</a>&gt;</code></p>
<p><a class="el" href="group__callback-when-writeable.html#ga8570860e191b62db264f2bac67354ea8">lws_callback_on_writable_all_protocol_vhost()</a> - Request a callback for all connections using the given protocol when it becomes possible to write to each socket without blocking in turn.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">vhost</td><td>Only consider connections on this lws_vhost </td></tr>
    <tr><td class="paramname">protocol</td><td>Protocol whose connections will get callbacks</td></tr>
  </table>
  </dd>
</dl>
<ul>
<li>Which: connections using this protocol on GIVEN VHOST ONLY</li>
<li>When: when the individual connection becomes writeable</li>
<li>What: LWS_CALLBACK_*_WRITEABLE </li>
</ul>

</div>
</div>
<a class="anchor" id="ga60939cf0c073d933fde3d17f3591caf5"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">LWS_VISIBLE LWS_EXTERN int lws_callback_vhost_protocols </td>
          <td>(</td>
          <td class="paramtype">struct lws *&#160;</td>
          <td class="paramname"><em>wsi</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>reason</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">void *&#160;</td>
          <td class="paramname"><em>in</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>len</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p><code>#include &lt;<a class="el" href="libwebsockets_8h.html">lib/libwebsockets.h</a>&gt;</code></p>
<p><a class="el" href="group__callback-when-writeable.html#ga60939cf0c073d933fde3d17f3591caf5">lws_callback_vhost_protocols()</a> - Callback all protocols enabled on a vhost with the given reason</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">wsi</td><td>wsi whose vhost will get callbacks </td></tr>
    <tr><td class="paramname">reason</td><td>Callback reason index </td></tr>
    <tr><td class="paramname">in</td><td>in argument to callback </td></tr>
    <tr><td class="paramname">len</td><td>len argument to callback</td></tr>
  </table>
  </dd>
</dl>
<ul>
<li>Which: connections using this protocol on same VHOST as wsi ONLY</li>
<li>When: now</li>
<li>What: reason </li>
</ul>

</div>
</div>
<a class="anchor" id="gac4643fe16b0940ae5b68b4ee6195cbde"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">LWS_VISIBLE LWS_EXTERN size_t lws_get_peer_write_allowance </td>
          <td>(</td>
          <td class="paramtype">struct lws *&#160;</td>
          <td class="paramname"><em>wsi</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p><code>#include &lt;<a class="el" href="libwebsockets_8h.html">lib/libwebsockets.h</a>&gt;</code></p>
<p><a class="el" href="group__callback-when-writeable.html#gac4643fe16b0940ae5b68b4ee6195cbde">lws_get_peer_write_allowance()</a> - get the amount of data writeable to peer if known</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">wsi</td><td>Websocket connection instance</td></tr>
  </table>
  </dd>
</dl>
<p>if the protocol does not have any guidance, returns -1. Currently only http2 connections get send window information from this API. But your code should use it so it can work properly with any protocol.</p>
<p>If nonzero return is the amount of payload data the peer or intermediary has reported it has buffer space for. That has NO relationship with the amount of buffer space your OS can accept on this connection for a write action.</p>
<p>This number represents the maximum you could send to the peer or intermediary on this connection right now without the protocol complaining.</p>
<p>lws manages accounting for send window updates and payload writes automatically, so this number reflects the situation at the peer or intermediary dynamically. </p>

</div>
</div>
<a class="anchor" id="gaa709e02a10558753c851e58f1e2c16ba"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">LWS_VISIBLE LWS_EXTERN int lws_get_socket_fd </td>
          <td>(</td>
          <td class="paramtype">struct lws *&#160;</td>
          <td class="paramname"><em>wsi</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p><code>#include &lt;<a class="el" href="libwebsockets_8h.html">lib/libwebsockets.h</a>&gt;</code></p>
<p><a class="el" href="group__callback-when-writeable.html#gaa709e02a10558753c851e58f1e2c16ba">lws_get_socket_fd()</a> - returns the socket file descriptor</p>
<p>You will not need this unless you are doing something special</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">wsi</td><td>Websocket connection instance </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.11 </li>
  </ul>
</div>
</body>
</html>
